﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;
namespace Human
{
	/// <summary>
	/// Summary description for frmDangKyLaoDong.
	/// </summary>
	public class frmDangKyLaoDong : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
		private DataSet ds =new DataSet();
        Language lan = new Language();
        string sql = "",m_user="",s_bophan="",user_dn="";		
		private System.Windows.Forms.Button butThoat;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butXem;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cboHd;
		private bool bClear=true;
		private System.ComponentModel.Container components = null;

		public frmDangKyLaoDong(string s_makp,string s_userdn)
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            s_bophan = s_makp;
            user_dn = s_userdn;
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmDangKyLaoDong));
            this.butThoat = new System.Windows.Forms.Button();
            this.butIn = new System.Windows.Forms.Button();
            this.butXem = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.cboHd = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // butThoat
            // 
            this.butThoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butThoat.Image = global::Human.Properties.Resources.close_r;
            this.butThoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThoat.Location = new System.Drawing.Point(165, 71);
            this.butThoat.Name = "butThoat";
            this.butThoat.Size = new System.Drawing.Size(62, 28);
            this.butThoat.TabIndex = 3;
            this.butThoat.Text = "Thoát";
            this.butThoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butThoat.Click += new System.EventHandler(this.butThoat_Click);
            // 
            // butIn
            // 
            this.butIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butIn.Image = global::Human.Properties.Resources.t_printer;
            this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butIn.Location = new System.Drawing.Point(99, 71);
            this.butIn.Name = "butIn";
            this.butIn.Size = new System.Drawing.Size(60, 28);
            this.butIn.TabIndex = 2;
            this.butIn.Text = "  In";
            this.butIn.Click += new System.EventHandler(this.butIn_Click);
            // 
            // butXem
            // 
            this.butXem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butXem.Image = global::Human.Properties.Resources.ok;
            this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butXem.Location = new System.Drawing.Point(33, 71);
            this.butXem.Name = "butXem";
            this.butXem.Size = new System.Drawing.Size(60, 28);
            this.butXem.TabIndex = 1;
            this.butXem.Text = "   Xem";
            this.butXem.Click += new System.EventHandler(this.butXem_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(16, 32);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(79, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Loại hợp đồng ";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // cboHd
            // 
            this.cboHd.Location = new System.Drawing.Point(99, 30);
            this.cboHd.Name = "cboHd";
            this.cboHd.Size = new System.Drawing.Size(121, 21);
            this.cboHd.TabIndex = 0;
            this.cboHd.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cboHd_KeyDown);
            // 
            // frmDangKyLaoDong
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(248, 116);
            this.Controls.Add(this.cboHd);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.butThoat);
            this.Controls.Add(this.butIn);
            this.Controls.Add(this.butXem);
            this.ForeColor = System.Drawing.Color.DarkBlue;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmDangKyLaoDong";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Đăng ký sử dụng lao động";
            this.Load += new System.EventHandler(this.frmDangKyLaoDong_Load);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmDangKyLaoDong_MouseMove);
            this.ResumeLayout(false);

		}
		#endregion

		private void butThoat_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void print(bool prn)
		{			
			string sql="SELECT l.manv,trim(l.ho)||' '||trim(l.ten) as hoten,l.namsinh,";
			sql += " l.phai as gioitinh,l.cmndso ,l.noisinh ,";
			sql += " dt.tendt as dantoc,tg.tentg as tongiao,l.diachi||', '||trim(q.tenquan)||', '||trim(t.tentt) as diachitt,";
			sql += " hv.tenhv as trinhdovh,trim(ct.tenctdt)||' - '||trim(bc.tenbang) as Chuyennganh,";
			sql += " cv.diengiai as chucvu,hd.hdldso as maso,";
			sql += " to_char(hd.tungay,'dd/mm/yyyy') as Ngayky,m.tenhd as loaihd,m.mahd as mahd,";
			sql += " l.sold as solaodong,hd.tgbhxh as thoigai_bhxh,";
			sql += " to_char(now(),'dd') as ngay,to_char(now(),'mm') as thang,to_char(now(),'yyyy') as nam,l.dkldso";
            sql += " ,round(hd.hs_lc*hd.luonghd) as luongcb";
            sql += " ,round((hd.hs_cv+(hd.hs_lc*hd.hs_vk)+hd.hs_dh+hd.hs_ld+hd.hs_tn+hd.hs_kv+hd.hs_th+(hd.hs_lc+hd.hs_cv+(hd.hs_lc*hd.hs_vk))*hd.hs_ud/100)*hd.luonghd) as luong_pc";
            sql += " From " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on hd.manv=l.manv";
            sql += " inner join " + m_user + ".dantoc dt on dt.madt=l.madt";
            sql += " inner join " + m_user + ".tongiao tg on tg.matgiao=l.matgiao";
            sql += " left join " + m_user + ".btdtt t on t.matt=l.t_diachi";
            sql += " left join " + m_user + ".btdquan q on q.maqu=l.h_diachi";
            sql += " left join " + m_user + ".dmcv cv on hd.macv=cv.macv";
            sql += " inner join " + m_user + ".mahd m on m.mahd=hd.loaihd";
            sql += " left join " + m_user + ".hocvan hv on hv.mahv=l.mahv ";
            sql += " left join " + m_user + ".ctdaotao ct on ct.mactdt=l.nnghiep";
            sql += " left join " + m_user + ".bangcap bc on l.td_nnghiep=bc.mabangcap";
            sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv ";
			sql += " where l.sold is null and hd.lan=ml.lan ";
            sql += " and (hd.ngaynghi is null or to_timestamp(hd.ngaynghi,'dd/mm/yyyy')> to_timestamp(to_char(now(),'dd/mm/yyyy'),'dd/mm/yyyy'))";
			if(cboHd.SelectedIndex!=-1) 
				sql+=" and m.mahd='"+cboHd.SelectedValue.ToString()+"'";
			ds=mDB.get_data(sql);
            ds.WriteXml("..\\xml\\h_dangkysudungld.xml", XmlWriteMode.WriteSchema);			
			if (ds.Tables[0].Rows.Count>0)
			{

                frmReport f = new frmReport(mDB, ds, "ĐĂNG KÝ SỬ DỤNG LAO ĐỘNG & CẤP SỔ LAO ĐỘNG", "h_dangkysudungld.rpt", true, user_dn);
				f.ShowDialog(this);
				
			}
			else
				MessageBox.Show("Chưa có đầy đủ dữ liệu","Thông Báo");
		}
		private void LoadHD()
		{
			cboHd.DisplayMember="tenhd";
			cboHd.ValueMember="mahd";
			cboHd.DataSource=mDB.get_data("SELECT * FROM "+m_user+".mahd").Tables[0];
		}

		private void frmDangKyLaoDong_Load(object sender, System.EventArgs e)
		{
            m_user = mDB.user;
            LoadHD();
		}

		private void frmDangKyLaoDong_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (bClear)
			{
				cboHd.SelectedIndex=-1;
				bClear=false;
			}
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{
			try
			{
				print(false);
			}
			catch{}
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
			try
			{
				print(true);
			}
			catch{}
		}

        private void cboHd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");	
        }

	}
}
